package com.testdemo.web.controller;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.testdemo.web.service.TestInfoService;
import com.testdemo.web.vo.TestInfo;

@Controller
@RequestMapping("/test")
public class TestInfoController {
	
	@Resource
	private TestInfoService infoService;
	
	@RequestMapping(value = "/get", 
			method = RequestMethod.GET)
	public ModelAndView getSeleteInfo(
			@RequestParam("id") int id){
		ModelAndView mav = new ModelAndView("testInfo");
		TestInfo info = infoService.selectById(id);
		mav.addObject("myTestInfo", info);
		return mav;
	}

	@RequestMapping(value = "/getjson", 
			method = RequestMethod.GET)
	public ModelAndView getJson( ){
		ModelAndView mav = new ModelAndView("test");
		return mav;
	}
	
	
	@RequestMapping(value = "/myjson", 
			method = RequestMethod.POST,
			consumes = MediaType.APPLICATION_JSON_VALUE, 
			produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public TestInfo myjson(@RequestBody String id)
	{
		TestInfo info = new TestInfo();
		info.setId(5);
		info.setName("232");
		info.setPsw("erw"); 
		return info;
	}
}
